#!/bin/bash
#
#  Command Line Interface to start all services associated with the Fast/Micro-RTPS tutorials
#
#  For this tutorial the commands are merely a convenience script to run docker-compose
#

set -e

stoppingContainers () {
	echo "Stopping containers"
	docker-compose --log-level ERROR -p fiware down -v --remove-orphans
}

if (( $# != 1 )); then
    echo "Illegal number of parameters"
    echo "usage: services [create|stop|stop]"
    exit 1
fi

command="$1"
case "${command}" in
	"help")
        echo "usage: services [create|start|stop]"
        ;;
    "start")
		stoppingContainers
		echo -e "Starting two containers - \033[1;30mFast-RTPS\033[0m and \033[1;30mMicro-RTPS\033[0m."
		docker-compose --log-level ERROR -p fiware up -d --remove-orphans
		;;
	"stop")
		stoppingContainers
		;;
	"create")
		echo "Building Docker images"
		docker-compose --log-level ERROR -p fiware build --no-cache --parallel --pull
		;;
	*)
		echo "Command not Found."
		echo "usage: services [create|start|stop]"
		exit 127;
		;;
esac